// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name:   EchoCommandHandler.java

package testmain;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.List;
import java.util.Map;


import com.dykj.fireFighting.web.model.report.DevHisSs;
import com.dykj.fireFighting.web.model.report.DevHisZc;
import org.quickserver.net.model.GB268753QN;
import org.quickserver.net.model.GB268753QNS;
import org.quickserver.net.model.GB268753QNSZGW;
import org.quickserver.net.server.*;
import org.quickserver.util.data.dataProcessing;

// Referenced classes of package testmain:
//            EchoServerData

public class EchoCommandHandler
    implements ClientCommandHandler, ClientEventHandler, ClientBinaryHandler
{

    public EchoCommandHandler()
    {
    }

    public void gotConnected(ClientHandler handler)
        throws SocketTimeoutException, IOException
    {
        handler.setDataMode(DataMode.BINARY, DataType.IN);
        handler.setDataMode(DataMode.BINARY, DataType.OUT);
        handler.sendSystemMsg((new StringBuilder("Connection on : ")).append(handler.getSocket().getInetAddress()).toString());
    }

    public void lostConnection(ClientHandler handler)
        throws IOException
    {
        handler.sendSystemMsg((new StringBuilder("Connection lost : ")).append(handler.getSocket().getInetAddress()).toString());
    }

    public void closingConnection(ClientHandler handler)
        throws IOException
    {
        handler.sendSystemMsg((new StringBuilder("Closing connection : ")).append(handler.getSocket().getInetAddress()).toString());
    }

    public void handleCommand(ClientHandler handler, String command)
        throws SocketTimeoutException, IOException
    {
        System.out.println(command);
        byte a[] = command.getBytes();
        System.out.println(stringToHexString(command));
        if(stringToHexString(command).equals("00"))
            handler.closeConnection();
        else
            handler.sendClientBinary(a);
    }

    public static String stringToHexString(String s)
    {
        String str = "";
        for(int i = 0; i < s.length(); i++)
        {
            int ch = s.charAt(i);
            String s4 = Integer.toHexString(ch);
            if(s4.length() == 1)
                s4 = (new StringBuilder("0")).append(s4).toString();
            str = (new StringBuilder(String.valueOf(str))).append(s4).toString();
        }

        return str;
    }

    public void handleBinary(ClientHandler handler, byte command[])
        throws SocketTimeoutException, IOException
    {
        EchoServerData ec = (EchoServerData)handler.getClientData();
        String a[] = dataProcessing.bytesToHexStrings(command);
        for(int i = 0; i < a.length; i++)
            System.out.println(a[i]);

    }

    public static byte[] hexStringToByteArray(String s)
    {
        int len = s.length();
        byte b[] = new byte[len / 2];
        for(int i = 0; i < len; i += 2)
            b[i / 2] = (byte)((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));

        return b;
    }

    public static final String bytesToHexString(byte bArray[])
    {
        StringBuffer sb = new StringBuffer(bArray.length);
        for(int i = 0; i < bArray.length; i++)
        {
            String sTemp = Integer.toHexString(0xff & bArray[i]);
            if(sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase());
        }

        return sb.toString();
    }

    public void handleBinaryStrings(ClientHandler handler, String strs[])
        throws SocketTimeoutException, IOException
    {
        for(int i = 0; i < strs.length; i++)
            System.out.println(strs[i]);

    }

    public void handleGB268753QN(ClientHandler handler, GB268753QN obj)
        throws SocketTimeoutException, IOException
    {
        if(obj != null)
        {
            System.out.println(obj.toString());
            System.out.println(obj.getUniqueCode());
        }
    }

    @Override
    public void handleGB268753QN(ClientHandler clienthandler, List<GB268753QNSZGW> gb268753qn) throws SocketTimeoutException, IOException {

    }

    @Override
    public void handleGB268753QN(ClientHandler clienthandler, DevHisSs obj) throws SocketTimeoutException, IOException {

    }

    public void handleGB268753QN(ClientHandler clienthandler, GB268753QNS obj)
			throws SocketTimeoutException, IOException {
		// TODO Auto-generated method stub
		if(obj != null)
        {
            System.out.println(obj.toString());
            System.out.println(obj.getUniqueCode());
        }
	}

    @Override
    public void handleGB268753QN(ClientHandler clienthandler, DevHisZc zcModel) throws SocketTimeoutException, IOException {
        if(zcModel != null)
        {
            System.out.println(zcModel.toString());
            System.out.println(zcModel.getDevCode());
        }
    }

    public void closingDev(ClientHandler handler, String uniqueCode)
        throws IOException
    {
        System.out.println((new StringBuilder(String.valueOf(uniqueCode))).append("close").toString());
    }

    public void lostDev(ClientHandler handler, String uniqueCode)
        throws IOException
    {
        System.out.println((new StringBuilder(String.valueOf(uniqueCode))).append("lost").toString());
    }

    public void gotConnectDev(ClientHandler handler, String uniqueCode)
        throws SocketTimeoutException, IOException
    {
        System.out.println((new StringBuilder(String.valueOf(uniqueCode))).append("conn").toString());
    }


}
